package com.charon.common.util;


import java.util.List;
import java.util.regex.Pattern;

/**
  *@ClassName: StringUtils
  *@Description: 字符串工具类
  *@Author: Moment
  *@Date: 2018/7/7 0007 22:08
  *@Version: 1.0
  */
public class StringUtils extends org.springframework.util.StringUtils {
    /**
     * @Author Moment
     * @Description 判断是否为整数,该方法为判断字符串是否为数字的最快方法
     * @Date 22:14 2018/7/7 0007
     * @param str 传入的字符串
     * @return 是整数返回true,否则返回false
     */
    public static boolean isInteger(String str) {
        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
        return pattern.matcher(str).matches();
    }

    /**
      * @Author Moment
      * @Description 是否为空
      * @Date 22:14 2018/7/7 0007
      * @Param s 字符串参数
      * @return 空返回false,否则返回true
      */
    public static boolean isEmpty(String s){
        if(s == null || s.length() <= 0||"".equals(s)){
            return false;
        }
        return true;
    }

    /**
     * @Description 判断两个字符串相等
     * @Author Charon [248135724@qq.com]
     * @Date 2019/1/29 23:22
     * @Param [a, b]
     * @return boolean
     */
    public static boolean equals(String a,String b){
        if(a==null||b==null)return false;
        return a.equals(b);
    }

    /**
     * @Description 判断两个字符串相等--忽略大小写。
     * @Author Charon [248135724@qq.com]
     * @Date 2019/1/29 23:25
     * @Param [a, b]
     * @return boolean
     */
    public static boolean equalsIgnoreCare(String a,String b){
        if(a==null||b==null)return false;
        return a.toLowerCase().equals(b.toLowerCase());
    }

    /**
     * @author Charon [248135724@qq.com]
     * @description List转字符串
     * @date 2019/1/31 0031 11:45
     * @param list
     * @return java.lang.String
     */
    public static String listToString(List list){
        return listToString(list,",");
    }

    /**
      * @author Charon [248135724@qq.com]
      * @description List转字符串
      * @date 2019/1/31 0031 11:45
      * @param list
      * @param separator 分隔符号
      * @return java.lang.String
      */
    public static String listToString(List list,String separator){
        if(list==null)return null;
        StringBuilder sb=new StringBuilder();
        for(Object obj : list){
            sb.append(((obj == null) ? "" : obj.toString())+separator);
        }
        return sb.toString();
    }


    public static String arrayToString(Object[] objects){
        return arrayToString(objects,",");
    }

    /**
     * Description: 数组转字符串
     * <p>Author: Charon [248135724@qq.com]
     * @Date 2019/2/1 14:43
     * @param objects 数组对象
     * @param separator 分隔符
     * @return java.lang.String
     */
    public static String arrayToString(Object[] objects,String separator){
        if(objects==null||objects.length<0)return null;
        StringBuilder sb=new StringBuilder();
        for(Object obj : objects){
            sb.append(((obj == null) ? "" : obj.toString())+separator);
        }
        return sb.toString();
    }



}
